@extends('Backstage.Layouts.layout')

@section('content')
    <div class="site-text site-block">
        <form class="layui-form layui-form-pane" action="">
            <input id="admin_role_id" name="id" type="hidden" value="{{$data->admin_role_id}}">
            {{csrf_field()}}
            <div class="layui-form-item">
                <label class="layui-form-label">角色名称</label>
                <div class="layui-input-inline">
                    <input value="{{$data->admin_role_name}}" maxlength="10" type="text" name="param[admin_role_name]" lay-verify="required" lay-vertype="tips"  autocomplete="off" placeholder="请输入名称" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">(限10个字内)</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">角色状态</label>
                <div class="layui-input-block">
                    <select name="param[admin_role_status]" lay-verify="required" lay-vertype="tips" >
                        @foreach($data->getStatusName('status','arr') as $key=>$val)
                            <option @if($data->admin_role_status == $key) selected="" @endif value="{{$key}}">{{$val}}</option>
                        @endforeach
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">管理节点</label>
                <div class="layui-input-block">
                    @foreach ($noteData as $val)

                            <?php $ischeck = false; ?>

                            @if (!empty($data['roleUser']))
                                @foreach ($data['roleUser'] as $roleUser)
                                    @if ($roleUser['admin_note_id'] == $val['admin_note_id'])
                                        <?php $ischeck = true; ?>
                                    @endif
                                @endforeach
                            @endif
                            @if (($val['admin_box'] == 1))
                                <hr class="layui-bg-green">
                            @endif
                            @if (($val['admin_note_default'] == 1))
                                <br>
                            @endif
                            <input type="checkbox" value="{{$val['admin_note_id']}}" name="param[role_user][]" title="{!! $val['admin_note_zh_name'] !!}" @if($ischeck) checked="" @endif>
                            @if (!empty($val['children']))
                                @foreach ($val['children'] as $children)

                                    <?php $ischeck = false; ?>

                                    @if (!empty($data['roleUser']))
                                        @foreach ($data['roleUser'] as $roleUser)
                                            @if ($roleUser['admin_note_id'] == $children['admin_note_id'])
                                                <?php $ischeck = true; ?>
                                            @endif
                                        @endforeach
                                    @endif

                                    @if (($children['admin_note_default'] == 1))
                                        <br>
                                    @endif

                                    <input type="checkbox" value="{{$children['admin_note_id']}}" name="param[role_user][]" title="{!! $children['admin_note_zh_name'] !!}" @if($ischeck) checked="" @endif>
                                    @if (($children['admin_box'] == 1))
                                        <hr class="layui-bg-green">
                                    @endif
                                @endforeach
                            @endif

                    @endforeach
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="form">立即提交</button>
                </div>
            </div>
        </form>
    </div>

@stop

@section('script')

    <script>
        layui.use(['upload','form'], function(){
            var form = layui.form;
            //监听提交
            form.on('submit(form)', function(data){

                var $this = $(data.elem);
                $this.attr('disabled', 'disabled');
                layer.msg('数据请求中···', {
                    icon: 16
                    ,shade: 0.01
                },0);
                $.ajax({
                    url: '{{URL::route('admin_role_save')}}',
                    data: data.field,
                    type: 'post',
                    cache: false,
                    dataType: 'json',
                    success: function (data) {
                        layer.closeAll();
                        if (data['status'] == 1) {

                            layer.msg(data['msg'], { icon: 1});
                            location.replace('{{URL::route('admin_role_index')}}');

                        } else {
                            layer.msg(data['msg'], { icon: 2});
                            $this.attr("disabled",false);
                        }
                        layer.closeAll();
                    },
                    error: function () {
                        layer.closeAll();
                        layer.msg('请求发生错误');
                        $this.attr("disabled",false);

                    }
                });

                return false;

            });
        });



    </script>
@stop

